<?php
// +----------------------------------------------------------------------
// | MYUPHP [ Simple and practical framework ]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-08-10 http://myuphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
namespace myuphp\Common;
class Session{  
      
        /** 
         * 设置session 
         * @param String $name   session name 
         * @param Mixed  $data   session data 
         * @param Int    $expire 超时时间(秒) 
         */  
        public static function set($name, $data, $expire=600){  
            $session_data = array();  
            $session_data['data'] = $data;  
            $session_data['expire'] = time()+$expire;  
            $_SESSION[$name] = $session_data;  
        }  
      
        /** 
         * 读取session 
         * @param  String $name  session name 
         * @return Mixed 
         */  
        public static function get($name){  
            if(isset($_SESSION[$name])){  
                if($_SESSION[$name]['expire']>time()){  
                    return $_SESSION[$name]['data'];  
                }else{  
                    self::clear($name);  
                }  
            }  
            return false;  
        }  
      
        /** 
         * 清除session 
         * @param  String  $name  session name 
         */  
        private static function clear($name){  
            unset($_SESSION[$name]);  
        }  
      
    }  